home *** CD-ROM | disk | FTP | other *** search
/ Aminet 23 / Aminet 23 (1998)(GTI - Schatztruhe)[!][Feb 1998].iso / Aminet / text / edit / Smartindent.lha / Smartindent / Source / LibFuncs.c < prev    next >
C/C++ Source or Header  |  1997-12-14  |  4KB  |  139 lines

  1. /*(( "Kopf" */
  2. /* -----------------------------------------------------------------------------
  3.  
  4.    $Id: LibFuncs.c,v 1.4 1997/06/26 14:27:02 mshopf Exp mshopf $
  5.  
  6.    GoldED API client, ©1997 Matthias Hopf.
  7.    Compiled with SasC.
  8.  
  9.  
  10.    Library entry functions.
  11.  
  12.    ------------------------------------------------------------------------------
  13. */
  14.  
  15. /*)) */
  16. /*(( "Includes" */
  17.  
  18. #include "compiler.h"
  19. #include "LibFuncs.h"
  20. #include "dispatcher.h"
  21. #include "util.h"
  22.  
  23. #include <proto/exec.h>
  24. #include <exec/types.h>
  25. #include <exec/memory.h>
  26.  
  27. #include <proto/intuition.h>
  28.  
  29. /*)) */
  30.  
  31. /*(( "General comments" */
  32.  
  33. /* Please note, that &ExampleBase always resides in register __a6 as well,
  34.    but if we don't need it, we need not reference it here.
  35.  
  36.    Also note, that registers a0, a1, d0, d1 always are scratch registers,
  37.    so you usually should only *pass* parameters there, but make a copy
  38.    directly after entering the function. To avoid problems of kind
  39.    "implementation defined behaviour", you should make a copy of A6 too,
  40.    when it is actually used.
  41. */
  42.  
  43. /*)) */
  44.  
  45. /*(( "L_MountClient ()" */
  46.  
  47. /***** Called once for every window it is used. *****/
  48.  
  49. struct APIClient * SAVEDS ASM L_MountClient (REG(a0) struct APIMessage *msg_    GNUCREG("a0"), REG(a1) char              *args_  GNUCREG("a1"))
  50. {
  51.     char *args = args_;
  52.     struct APIMessage *msg = msg_;
  53.     sc_t *c;
  54.  
  55.     if (! (c = AllocMem (sizeof (sc_t), MEMF_PUBLIC | MEMF_CLEAR)))
  56.     return NULL;
  57.  
  58.     if (! ScanArgs (c, args, msg))
  59.     {
  60.     FreeMem (c, sizeof (sc_t));
  61.     return NULL;
  62.     }
  63.  
  64. #if API_INTERFACE_VERSION != 3
  65. #  error "This client needs headers for API interface version 3
  66. #endif
  67.  
  68.     c->API.api_APIVersion = API_INTERFACE_VERSION;
  69.     c->API.api_Version    = 1;
  70.     c->API.api_Name       = "Smartindent API";
  71.     c->API.api_Info       = "Indenting C and other code";
  72.     c->API.api_Commands   = apiCommands;
  73.     c->API.api_Serial     = 0;
  74.     c->API.api_Classes    = API_CLASS_COMMAND | API_CLASS_KEY;
  75.     c->API.api_Area       = NULL;
  76.  
  77.     return ((struct APIClient *) c);
  78. }
  79.  
  80.  
  81. /*)) */
  82. /*(( "L_CloseClient ()" */
  83.  
  84. void               SAVEDS ASM L_CloseClient (REG(a0) struct APIClient  *client_ GNUCREG("a0"), REG(a1) struct APIMessage *msg_   GNUCREG("a1"))
  85. {
  86.     /* we don't save the arguments, because we only call a function and don't need them afterwards */
  87.     FreeMem (client_, sizeof (sc_t));
  88. }
  89.  
  90.  
  91. /*)) */
  92. /*(( "L_BriefClient ()" */
  93.  
  94. /***** Notify Routine. This is called for all event classes specified above. *****/
  95.  
  96. void               SAVEDS ASM L_BriefClient (REG(a0) struct APIClient  *client_ GNUCREG("a0"), REG(a1) struct APIMessage *msg_   GNUCREG("a1"))
  97. {
  98.     sc_t *client = (sc_t *) client_;
  99.     struct APIMessage  *msg    = msg_;
  100.  
  101.     while (msg)
  102.     {
  103.     if (msg->api_State == API_STATE_NOTIFY)
  104.     {
  105.         switch (msg->api_Class) {
  106.         case API_CLASS_KEY:
  107.         if (msg->api_Action == API_ACTION_VANILLAKEY)
  108.             DispatchKey (client, msg);
  109.         break;
  110. // case API_CLASS_SYSTEM:  /* currently unused */
  111.         case API_CLASS_COMMAND:
  112.         if (msg->api_Action == API_ACTION_COMMAND)
  113.             DispatchCmd (client, msg);
  114.         else
  115.             msg->api_Error = API_ERROR_UNKNOWN;
  116.         break;
  117.  
  118.         default:
  119.         msg->api_Error = API_ERROR_UNKNOWN;
  120.         }
  121.     }
  122.     msg = msg->api_Next;
  123.     }
  124. }
  125.  
  126.  
  127. /*)) */
  128. /*(( "L_Free ()" */
  129.  
  130. /***** Order structure is consumed by Host and we may now free it. *****/
  131. void               SAVEDS ASM L_Free        (REG(a0) struct APIClient  *client GNUCREG("a0"), REG(a1) struct APIOrder   *order GNUCREG("a1"))
  132. {
  133.     /* we don't save the arguments, because we only call a function and don't need them afterwards */
  134.     FreeRequest ((sc_t *) client, (struct SmartOrder *) order);
  135. }
  136.  
  137.  
  138. /*)) */
  139.